Imports System.Drawing

Public Class Debug

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim c As Comunicacao

        ListBox1.Items.Clear()

        c = New Comunicacao
        c.Conectar()

    End Sub



    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If Cliente.GetEstado <> "Conectado" Then
            lblStatus.ForeColor = Drawing.Color.Red
            lblStatus.Font = New Font(lblStatus.Font, FontStyle.Regular)
            Dim c As Comunicacao
            c = New Comunicacao
            c.Conectar()
        Else
            lblStatus.ForeColor = Drawing.Color.DarkGreen
            lblStatus.Font = New Font(lblStatus.Font, FontStyle.Bold)
        End If

        Dim i As Integer

        lblStatus.Text = Cliente.GetEstado()
        ListBox1.Items.Clear()

        Try

            If Comunicacao.Log.Items.Count > ListBox1.ItemHeight Then
                For i = Comunicacao.Log.Items.Count - ListBox1.ItemHeight To Comunicacao.Log.Items.Count - 1
                    ListBox1.Items.Add(Comunicacao.Log.Items(i))
                Next
            Else
                For i = 0 To Comunicacao.Log.Items.Count - 1
                    ListBox1.Items.Add(Comunicacao.Log.Items(i))
                Next
            End If

            If ListBox1.Items.Count > 0 Then
                ListBox1.SelectedIndex = ListBox1.Items.Count - 1
            End If

        Catch ex As Exception
            ListBox1.Items.Add(ex.Message)
            ListBox1.Items.Add("")
            ListBox1.Items.Add(ex.StackTrace)
        End Try

    End Sub

    Private Sub Debug_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Comunicacao.Desconectar()
    End Sub

    Private Sub Debug_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Cliente As New Cliente
        Dim c As New Config

        txtServidor.Text = c.Servidor
        txtPorta.Text = c.Porta
        txtPath.Text = c.Path

        Dim comunic As Comunicacao

        ListBox1.Items.Clear()

        comunic = New Comunicacao
        comunic.Conectar()

    End Sub


    Private Sub btnGravar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGravar.Click
        Dim c As New Config
        c.setServidor(txtServidor.Text)
        c.setPorta(txtPorta.Text)
        c.setPath(txtPath.Text)
    End Sub

    Protected Overrides Sub Finalize()
        Comunicacao.Desconectar()
        MyBase.Finalize()
    End Sub
End Class